from django.db import models

# Create your models here.


class BookInfo(models.Model):
    """图书信息：演示⼀对多，⼀⽅"""
    btitle = models.CharField(max_length=20, verbose_name='书名')
    bpub_date = models.DateField(verbose_name='发布⽇期')
    bread = models.IntegerField(default=0, verbose_name='阅读量')
    bcomment = models.IntegerField(default=0, verbose_name='评论量')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')


    class Meta:
        """模型类的元类：⽤于修改、配置模型类对应的数据表"""
        db_table = 'tb_books'  # ⾃定义数据库表名

    def __str__(self):

        return self.btitle  # 输出该模型数据对象时，只输出书名


class HeroInfo(models.Model):
    """英雄信息：演示⼀对多，多⽅"""
    # 确定性别字段的取值范围
    GENDER_CHOICES = (
        (0, 'female'),
        (1, 'male')
    )
    # 外键属性是hbook
    hbook = models.ForeignKey(BookInfo, on_delete=models.CASCADE, verbose_name='英雄属于的图书')
    hname = models.CharField(max_length=20, verbose_name='⼈名')
    hgender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0, verbose_name='性别')
    hcomment = models.CharField(max_length=200, null=True, verbose_name='描述信息')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_heros'

    def __str__(self):
        return self.hname